package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

type RywResponse struct {
	Code int         `json:"code"`
	Data interface{} `json:"data"`
	Msg  string      `json:"msg"`
}

const (
	ERROR   = 7
	SUCCESS = 0
)

// Result 返回结果
func Result(resp *RywResponse, c *gin.Context) {
	c.JSON(http.StatusOK, &resp)
}

// SuccessWithMsg 成功的返回
func SuccessWithMsg(msg string) *RywResponse {
	return &RywResponse{
		Code: SUCCESS,
		Data: "",
		Msg:  msg,
	}
}

// SuccessWithData 成功的返回
func SuccessWithData(data interface{}, msg string) *RywResponse {
	return &RywResponse{
		Code: SUCCESS,
		Data: data,
		Msg:  msg,
	}
}

// FailWithMsg 失败的返回
func FailWithMsg(msg string) *RywResponse {
	return &RywResponse{
		Code: ERROR,
		Data: "",
		Msg:  msg,
	}
}
